package com.future.network.info

import com.future.network.NetworkType

abstract class CommonNetworkStateController : NetworkController {

    private var oldNetworkType: NetworkType? = null

    override fun networkType(networkType: NetworkType) {
        when (networkType) {
            NetworkType.NETWORK_WIFI -> {
                if (oldNetworkType == NetworkType.NETWORK) {
                    mobile2wifi()
                }
                oldNetworkType = networkType
                currentNetwork(networkType)
            }
            NetworkType.NETWORK -> {
                if (oldNetworkType == NetworkType.NETWORK_WIFI) {
                    wifi2mobile()
                }
                oldNetworkType = networkType
                currentNetwork(networkType)
            }
            NetworkType.NETWORK_NO -> {
                lostNet()
            }
            NetworkType.RECONNECTION -> {
                netReconnecting()
            }
            NetworkType.NETWORK_UNKNOWN -> {
                currentNetwork(networkType)
            }
            else -> {

            }
        }

    }

    /**
     * 网络丢失
     */
    open fun lostNet() {}

    /**
     * WiFi网络切换到移动
     */
    open fun wifi2mobile() {}

    /**
     *移动网络切换到WiFi
     */
    open fun mobile2wifi() {}

    /**
     * 网络重连中
     */
    open fun netReconnecting() {}

    open fun currentNetwork(networkType: NetworkType) {}

}